#include <iostream>
#include <cstring>
using namespace std;

const int N = 2e5;
int T, n, A[N + 3], C[N + 3], ans, sta[N + 3];
void solve(int dep, int n) {
    if (dep == n + 1) {
        memset(C, 0, sizeof C);
        for (int i = 1; i <= n; i++) {
            for (int j = i - 1; j >= 1; j--) {
                if (sta[i] == sta[j]) {
                    if (A[i] == A[j]) C[i] = A[i];
                    break;
                }
            }
        }
        int sum = 0;
        for (int i = 1; i <= n; i++) sum += C[i];
        ans = max(ans, sum);
        return;
    }
    sta[dep] = 0;
    solve(dep + 1, n);
    sta[dep] = 1;
    solve(dep + 1, n);
    return;
}
int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> T;
    while (T--) {
        ans = 0;
        memset(A, 0, sizeof A);
        memset(C, 0, sizeof C);
        cin >> n;
        for (int i = 1; i <= n; i++) cin >> A[i];
        solve(1, n);
        cout << ans << '\n';
    }
    return 0;
}
